using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Emlyn.Common.Data.DBUpdater;
using Emlyn.Website.Articles;
using System.Collections;
using Emlyn.Website.ArticlesPresentation;
using System.Collections.Generic;

public partial class _Default : EmlynPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            new Emlyn.Website.EmlynORegan.DBUpdateRules.DUR_0010_tblEOWebsite();
            // forces the assembly to be loaded

            DBUpdaterMain ldbupdater = new DBUpdaterMain();

            if (ldbupdater.NeedsUpgrade())
            {
                ldbupdater.UpgradeDB();
                lblMessage.Text = "Upgraded DB";
            }

            // Set up main descriptive info
            Literal litMain = new Literal();

            ArticleQuery larticleQuery = new ArticleQuery();
            Article lmainArticle = larticleQuery.GetArticleByArticleCode("EOMain");
            if (lmainArticle != null)
            {
                Label lmainLabel = new Label();
                lmainLabel.Text = lmainArticle.ArticleContent;

                pnlBodyMain.Controls.Add(lmainLabel);
            }

            // Set up front page blog
            Article lfrontPageBlogArticle = larticleQuery.GetArticleByArticleCode("EOFPBlog");

            if (lfrontPageBlogArticle != null)
            {
                IList<Article> lblogArticles = larticleQuery.GetArticlesForParentArticleID(lfrontPageBlogArticle.ArticleID);

                PresentArticleList lpal = new PresentArticleList();
                PresentArticleDetailFactory lpadf = new PresentArticleDetailFactory();
                lpadf.IncludeDateInDisplayName = true;
                lpal.aPresentArticleFactory = lpadf;
                lpal.aPresentArticleFactory.aEditable = false;
                //lpal.Title = "Front Page Blog:";
                lpal.aArticleList = lblogArticles;

                pnlBodyBlog.Controls.Add(lpal);
            }

            // Set up front page news
            Article lfrontPageNewsArticle = larticleQuery.GetArticleByArticleCode("EOFPNews");

            if (lfrontPageNewsArticle != null)
            {
                IList<Article> lnewsArticles = larticleQuery.GetArticlesForParentArticleID(lfrontPageNewsArticle.ArticleID);

                PresentArticleList lpal = new PresentArticleList();
                PresentArticleDetailFactory lpadf = new PresentArticleDetailFactory();
                lpadf.IncludeDateInDisplayName = true;
                lpal.aPresentArticleFactory = lpadf;
                lpal.aPresentArticleFactory.aEditable = false;
                //lpal.aPresentArticleFactory.aCSSPrefix = "News";
                lpal.CssClass = "News";
                lpal.Title = "News:";
                lpal.aArticleList = lnewsArticles;

                pnlRight.Controls.Add(lpal);
            }
        }
    }
}
